home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / MBUF.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-24  |  2.1 KB  |  70 lines

  1. #ifndef    _MBUF_H
  2. #define    _MBUF_H
  3.  
  4. #ifndef _STDIO_H_
  5. #define _STDIO_H_    1
  6. #include <stdio.h>
  7. #endif
  8.  
  9. #ifndef _GLOBAL_H
  10. #include "global.h"
  11. #endif
  12.  
  13. /* Basic message buffer structure */
  14. struct mbuf {
  15.     struct mbuf *next;    /* Links mbufs belonging to single packets */
  16.     struct mbuf *anext;    /* Links packets on queues */
  17.     int16 size;        /* Size of associated data buffer */
  18.     int refcnt;        /* Reference count */
  19.     struct mbuf *dup;    /* Pointer to duplicated mbuf */
  20.     unsigned char *data;    /* Active working pointers */
  21.     int16 cnt;
  22. };
  23. #define    NULLBUF    (struct mbuf *)0
  24. #define    NULLBUFP (struct mbuf **)0
  25.  
  26. #define    PULLCHAR(bpp)\
  27.  ((bpp) != NULL && (*bpp) != NULLBUF && (*bpp)->cnt > 1 ? \
  28.  ((*bpp)->cnt--,(unsigned char)*(*bpp)->data++) : pullchar(bpp))
  29.  
  30. /* In mbuf.c: */
  31. struct mbuf *alloc_mbuf (int16 size);
  32. struct mbuf *free_mbuf (struct mbuf *bp);
  33.  
  34. struct mbuf *ambufw (int16 size);
  35. struct mbuf *copy_p (struct mbuf *bp,int16 cnt);
  36. int16 dup_p (struct mbuf **hp,struct mbuf *bp,int16 offset,int16 cnt);
  37. struct mbuf *free_p (struct mbuf *bp);
  38. int16 len_p (struct mbuf *bp);
  39. void trim_mbuf (struct mbuf **bpp,int16 length);
  40. int write_p (FILE *fp,struct mbuf *bp);
  41.  
  42. struct mbuf *dequeue (struct mbuf **q);
  43. void enqueue (struct mbuf **q,struct mbuf *bp);
  44. void free_q (struct mbuf **q);
  45. int16 len_q (struct mbuf *bp);
  46.  
  47. struct mbuf *qdata (const unsigned char *data,int16 cnt);
  48. int16 dqdata (struct mbuf *bp,unsigned char *buf,unsigned cnt);
  49.  
  50. void append (struct mbuf **bph,struct mbuf *bp);
  51. struct mbuf *pushdown (struct mbuf *bp,int16 size);
  52. int16 pullup (struct mbuf **bph,unsigned char *buf,int16 cnt);
  53.  
  54. int pullchar (struct mbuf **bpp);       /* returns -1 if nothing */
  55. int16 pull16 (struct mbuf **bpp);    /* returns -1 if nothing */
  56. uint32 pull32 (struct mbuf **bpp);    /* returns  0 if nothing */
  57.  
  58. int16 get16 (char *cp);
  59. uint32 get32 (char *cp);
  60. unsigned char *put16 (unsigned char *cp,int16 x);
  61. unsigned char *put32 (unsigned char *cp,uint32 x);
  62.  
  63. #ifndef UNIX
  64. void mbuf_crunch (struct mbuf **bpp);
  65. #endif
  66.  
  67. #define AUDIT(bp)       audit(bp,__FILE__,__LINE__)
  68.  
  69. #endif    /* _MBUF_H */
  70.